import java.util.*;
import java.io.*;

public class test {
    // 蓝桥杯 保险箱(⭐⭐⭐)
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String x = in.next();
        String y = in.next();
        int[] a = new int[n + 5];
        int[] b = new int[n + 5];
        for (int i = n - 1; i >= 0; i--) {
            a[i + 1] = x.charAt(i) - '0';
            b[i + 1] = y.charAt(i) - '0';
        }
        int[][] dp = new int[n + 5][3];
        // 从右往左进位,所以从右往左遍历.
        // 初始化第一个元素(最后一个开始)
        // [0]代表不进位 [1]代表进位1 [2]代表进位-1
        int num = a[n] - b[n];
        dp[n][0] = Math.abs(a[n] - b[n]);
        dp[n][1] = 10 - num; // 如:3->7  3,4,5...16,17
        dp[n][2] = 10 + num; // 如:3->7  3,2,1...8,7
        for (int i = n - 1; i >= 1; i--) {
            int h = a[i] - b[i];
            int ab1 = h;
            int ab2 = h + 1;//进位1得来,比正常+1
            int ab3 = h - 1;//进位-1得来,比正常-1
            dp[i][0] = findMin(dp[i + 1][0] + Math.abs(ab1),
                    dp[i + 1][1] + Math.abs(ab2), dp[i + 1][2] + Math.abs(ab3));
            dp[i][1] = findMin(dp[i + 1][0] - ab1 + 10,
                    dp[i + 1][1] - ab2 + 10, dp[i + 1][2] - ab3 + 10);
            dp[i][2] = findMin(dp[i + 1][0] + ab1 + 10,
                    dp[i + 1][1] + ab2 + 10, dp[i + 1][2] + ab3 + 10);
        }
        System.out.println(findMin(dp[1][0], dp[1][1], dp[1][2]));
        in.close();
        // 123 -> 137 -> 157 ->
        // 567    ()
    }

    public static int findMin(int a, int b, int c) {
        return Math.min(a, Math.min(b, c));
    }

    // 蓝桥杯 健身(⭐⭐⭐)
    public static int[][] nums;
    public static int len;

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int q = in.nextInt();
        // 完全背包问题:
        // "所需天数"代表"物品重量"
        // "健身增益"代表"物品价值"
        // 那么此时,我们已知"健身天数"和"其他安排的日子"
        // 将其他安排的日子去掉,就能将健身天数分出多段,每一段都可以当作一个背包
        // 这样分别填充每个背包,最后得到的就是最大收益
        // twos用于存储2^k可能存在的天数
        int[] twos = new int[21];
        int sum = 1;
        for (int i = 0; i <= 20; i++) {
            twos[i] = sum;
            sum *= 2;
        }
        //存储背包大小和该背包个数
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] day = new int[q];
        day[0] = in.nextInt();
        for (int i = 1; i < q; i++) {
            day[i] = in.nextInt();
            int tmp = day[i] - day[i - 1] - 1;
            map.put(tmp, map.getOrDefault(tmp, 0) + 1);
        }
        map.put(day[0] - 1, map.getOrDefault(day[0] - 1, 0) + 1);
        map.put(n - day[q - 1], map.getOrDefault(n - day[q - 1], 0) + 1);
        // [0]代表第i个健身计划需要的天数
        // [1]代表第i个健身计划得到的健身增益
        nums = new int[m + 1][2];
        for (int i = 0; i < m; i++) {
            int k = in.nextInt();
            int s = in.nextInt();
            nums[i][0] = twos[k];
            nums[i][1] = s;
        }
        System.out.println(nums[0][1]);
        len = m;
        long Sum = 0;
        for (Map.Entry<Integer, Integer> tmp : map.entrySet()) {
            int llen = tmp.getValue();
            for (int i = 0; i < llen; i++) {
                Sum += bag(tmp.getKey());
                //System.out.println(tmp.getKey() + " " + bag(tmp.getKey()));
            }
        }
        System.out.println(Sum);
    }

    public static long bag(int max) {
        // 放入第i个物品时,背包内剩余j的容量
        long[] dp = new long[max + 5];
        for (int i = 0; i < len; i++) {
            int v = nums[i][0];
            long w = nums[i][1];
            for (int j = 0; j <= max; j++) {
                if (j >= v) {
                    dp[j] = Math.max(dp[j], dp[j - v] + w);
                }
            }
        }
        return dp[max];
    }
}